<HTML><HEAD><TITLE>view_graph(+Graph, +Options)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">library(graphviz)</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>view_graph(+Graph, +Options)</H1>
Display a given graph in a window
<DL>
<DT><EM>Graph</EM></DT>
<DD>A graph structure
</DD>
<DT><EM>Options</EM></DT>
<DD>A list of Option:Value pairs
</DD>
</DL>
<H2>Description</H2>

    This predicate takes a graph, applies one of the graphviz layout routines
    to it, and displays the result in a viewer window.
    <P>
    Possible options are:
    <DL>
    <DT>graph_attrs</DT>
	<DD>a list of Name=Value pairs which specify the graph attributes</DD>
    <DT>default_edge_attrs</DT>
	<DD>a list of Name=Value pairs which specify the default edge attributes</DD>
    <DT>default_node_attrs</DT>
	<DD>a list of Name=Value pairs which specify the default node attributes</DD>
    <DT>node_attrs_generator</DT>
	<DD>a partialpredicate specification pred(ExtraArgs,...) that
	will generate node attributes for specific nodes. This
	predicate will be invoked for every node in the graph with the
	arguments pred(ExtraArgs,...,+Graph, +Node, -AttrList). It is
	expected to compute an attribute list for a particular
	node. If it fails, the node will be displayed using the
	default node attributes.</DD>

    <DT>edge_attrs_generator</DT>
	<DD>a partialpredicate specification pred(ExtraArgs,...) that
	will generate edge attributes for specific edges. This
	predicate will be invoked for every edge in the graph with the
	arguments pred(ExtraArgs,...,+Graph, +Edge, -AttrList). It is
	expected to compute an attribute list for a particular
	edge. If it fails, the edge will be displayed using the
	default edge attributes.</DD>
    <DT>layout</DT>
	<DD>One of the atoms: none, dot, neato, twopi, force_directed, radial,
	tree, top_to_bottom, left_to_right.
	Alternatively, a list specifying a layout command (see exec/3).
    </DL>
    For the exact definition of graph, node and edge attributes, see the
    specification of the DOT language in the graphviz documentation.
    
<H3>Modules</H3>
This predicate is sensitive to its module context (tool predicate, see @/2).
<H2>Examples</H2>
<PRE>
    ?- lib(graph_algorithms), lib(graphviz).
    Yes (1.17s cpu)

    ?- make_random_graph(10, 30, true, true, true, G),
       view_graph(G, [layout:left_to_right]).
    G = graph(...)
    Yes (0.03s cpu)

    ?- make_random_graph(10, 30, true, true, true, G),
       view_graph(G, [layout:left_to_right]).
    G = graph(...)
    Yes (0.03s cpu)


% Sample node attribute generator

node_colour(Graph, Node, Attrs) :-
	( Node mod 2 =:= 0 -&gt; Attrs = [color=red] ; Attrs = [color=green] ).

% Sample run

    ?- make_random_graph(10, 30, true, true, true, G),
       view_graph(G, [node_attrs_generator:node_colour]).
    G = graph(...)
    Yes (0.03s cpu)
    </PRE>
<H2>See Also</H2>
<A HREF="../../lib/graphviz/view_graph-1.html">view_graph / 1</A>, <A HREF="../../lib/graph_algorithms/index.html">library(graph_algorithms)</A>
</BODY></HTML>
